import 'package:flutter/material.dart';
import 'package:honeypotflutter/public/public_date.dart';
import 'package:honeypotflutter/publicBussine/bussine_colors.dart';
import '../model/cabinet_form_deliver_info_model.dart';

class CabinetFormDeliverInfoItem extends StatelessWidget {
  final ScrollController? controller;
  final bool isScroll;
  final CabinetDeliverListInfoModel? model;
  const CabinetFormDeliverInfoItem({
    super.key,
    this.controller,
    this.isScroll = true,
    this.model,
  });

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        _rowWidget(title: (model != null) ? HLDate.hl_format(date: model!.date) : "日期", width: 100),
        Expanded(
            child: Container(
          height: 50,
          child: SingleChildScrollView(
            controller: controller,
            scrollDirection: Axis.horizontal,
            physics: isScroll ? ScrollPhysics() : NeverScrollableScrollPhysics(),
            child: Row(
              children: [
                _rowWidget(title: _showContent(replace: "总投递量", count: model?.totalCount), width: 120),
                _rowWidget(title: _showContent(replace: "韵达", count: model?.yundaCount)),
                _rowWidget(title: _showContent(replace: "中通", count: model?.ztoCount)),
                _rowWidget(title: _showContent(replace: "申通", count: model?.stoCount)),
                _rowWidget(title: _showContent(replace: "圆通", count: model?.ytoCount)),
                _rowWidget(title: _showContent(replace: "邮政", count: model?.chinaPostCount)),
                _rowWidget(title: _showContent(replace: "极兔", count: model?.jtCount)),
                _rowWidget(title: _showContent(replace: "顺丰", count: model?.sfCount)),
                _rowWidget(title: _showContent(replace: "京东", count: model?.jdCount)),
                _rowWidget(title: _showContent(replace: "其他", count: model?.elseCount)),
              ],
            ),
          ),
        ))
      ],
    );
  }

  String _showContent({int? count, required String replace}) {
    if (count == null) {
      return replace;
    }
    return count.toString();
  }

  Widget _rowWidget({double width = 80, String? title, Color? color}) {
    return Container(
      color: MGColors.whileColor,
      padding: EdgeInsets.only(left: 12, right: 12),
      width: width,
      height: 50,
      child: Row(
        children: [
          Text(
            title ?? "",
            textAlign: TextAlign.center,
            style: TextStyle(color: color ?? MGColors.text3Color),
          )
        ],
      ),
    );
  }
}
